//
//  CompanyInfoTableViewCell.m
//  LubanWork
//
//  Created by xiaotong on 2020/1/2.
//  Copyright © 2020 xiaohao. All rights reserved.
//

#import "CompanyInfoTableViewCell.h"

@implementation CompanyInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.compnyInfoLab];
        [self.contentView addSubview:self.companyName];
        [self.contentView addSubview:self.compnyImage];
        [self.contentView addSubview:self.scoreLab];
        [self.compnyInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(kSCRATIO(20));
            make.left.equalTo(self.contentView).offset(kSCRATIO(35));
            make.height.mas_offset(kSCRATIO(15));
            make.right.equalTo(self.contentView.mas_right).offset(-kSCRATIO(35));
        }];
        
        [self.compnyImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(kSCRATIO(25));
            make.top.equalTo(self.compnyInfoLab.mas_bottom).offset(kSCRATIO(20.5));
            make.width.height.mas_offset(kSCRATIO(40));
        }];
        
        [self.companyName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.compnyImage.mas_right).offset(kSCRATIO(10));
            make.top.equalTo(self.compnyImage).offset(kSCRATIO(4));
            make.height.mas_offset(kSCRATIO(13));
            make.right.equalTo(self.contentView.mas_right).offset(-kSCRATIO(10));
        }];
        
        [self.scoreLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.compnyImage.mas_right).offset(kSCRATIO(10.5));
            make.bottom.equalTo(self.compnyImage.mas_bottom).offset(-kSCRATIO(4));
            make.height.mas_offset(kSCRATIO(12));
            make.width.mas_offset(kSCRATIO(50));
        }];
        
        for (int i= 0; i < 5; i++) {
            UIImageView *image = [[UIImageView alloc] init];
            [self.contentView addSubview:image];
            image.image = [UIImage imageNamed:@"score"];
            [image mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.scoreLab.mas_right).offset(6.5+(i*(11+4)));
                make.centerY.equalTo(self.scoreLab.mas_centerY);
                make.width.height.mas_offset(kSCRATIO(11));
            }];
            [self.scoreArray addObject:image];
        }
    }
    return self;
}

-(UILabel *)compnyInfoLab{
    if (!_compnyInfoLab) {
        _compnyInfoLab = [UILabel CreatLabeltext:@"[公司信息]" Font:kFONT(15) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
    }
    return _compnyInfoLab;
}

-(UILabel *)companyName{
    if (!_companyName) {
        _companyName = [UILabel CreatLabeltext:@"北京xxxxxx有限公司" Font:kFONT(13) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
    }
    return _companyName;
}

-(UIImageView *)compnyImage{
    if (!_compnyImage) {
        _compnyImage = [[UIImageView alloc] init];
        _compnyImage.backgroundColor = kColorFromRGBHex(0x775FFB);
        ViewRadius(_compnyImage, kSCRATIO(20));
    }
    return _compnyImage;
}

-(UILabel *)scoreLab{
    if (!_scoreLab) {
        _scoreLab = [UILabel CreatLabeltext:@"综合评分" Font:kFONT(12) Textcolor:kColorFromRGBHex(0x666666) textAlignment:NSTextAlignmentLeft];
    }
    return _scoreLab;
}

-(NSMutableArray *)scoreArray{
    if (!_scoreArray) {
        _scoreArray = [NSMutableArray array];
    }
    return _scoreArray;
}

-(void)setScoreWithNumber:(NSInteger)number{
    if (number < 0 && number >= self.scoreArray.count)return;
    for (int i = 0; i < number; i++) {
        UIImageView *image = self.scoreArray[i];
        image.image = [UIImage imageNamed:@"score_select"];
    }
}
@end
